#!/usr/bin/env dash


coded_by='

In the name of Allah, the most Gracious, the most Merciful.

 ▓▓▓▓▓▓▓▓▓▓
░▓ Author ▓ Abdullah <https://abdullah.today>
░▓▓▓▓▓▓▓▓▓▓
░░░░░░░░░░

░█▀▄░█▀▀░█▀█░█░█░█▄█
░█▀▄░▀▀█░█▀▀░█▄█░█░█
░▀▀░░▀▀▀░▀░░░▀░▀░▀░▀
'

# Define some functions

multimonitors()
{
  start_from=1
  monitors_connected=$(bspc query -M | wc -l)
  per_monitor=$(( 10 / monitors_connected ))
  for monitor in $(bspc query -M); do
    bspc monitor $monitor -d $(seq $start_from $(( start_from + per_monitor - 1)))
    start_from=$(( start_from + per_monitor ))
 done
}

multibar() {
  # check how many monitors are connected and start polybar on all of them.
  pkill polybar
  while pgrep -x polybar >/dev/null; do sleep 1; done
  xrandr -q | awk '/ connected / {print $1}' | while read -r monitor _; do
  polybar -r "$monitor" &
done
}

# Divide workspaces/desktops to all connected monitors

multimonitors

for monitor in unplugged disabled ; do
  bspc config \
    remove_${monitor}_monitors      true
done

bspc config \
  merge_overlapping_monitors        true

# Rules for windows

bspc config external_rules_command "$HOME"/.config/bspwm/external_rules

# Start polybar on all connected monitors

# multibar &
# Start stalonetray
# stalonetray &
# Start lemonbar
#$HOME/.local/bin/mypanel &
#SXHKD_SHELL=`which dash` sxhkd &

# Border width and gaps between windows

border_width=1
window_gaps=5
bspc config border_width            $border_width
bspc config window_gap              $window_gaps

# Padding

padding="0"
for side in right bottom left ; do
  bspc config ${side}_padding       $padding
done

for side in top right bottom left; do
    bspc config ${side}_monocle_padding 0
done

# Ignore EWMH focus requests. If true, opening new program in already
# opened instance will have direct
# focus too. Like if you're on desktop 8 and you open a URL from mutt, and
# chrome is configured as url launcher, it will send the url to chrome opened
# in 2nd desktop and switch to it.

bspc config ignore_ewmh_focus       false

# On which child should a new window be attached

bspc config initial_polarity        second_child

# Split ration for new windows

bspc config split_ratio             0.50

# If monocle layout, no border to windows.

bspc config borderless_monocle      true

# No gaps as well

bspc config gapless_monocle         true

# Move focus from tiled windows to floating

bspc config directional_focus_tightness low

# Focus the window under the pointer

bspc config focus_follows_pointer   true

# When focusing a monitor/window, put the pointer to its center.

bspc config pointer_follows_monitor true
bspc config pointer_follows_focus   false

# Button used to focusing a window/monitor

bspc config click_to_focus          any

# if there is only one window, set the layout monocle.

bspc config single_monocle          true

# Pointer actions when pressing mod + button

bspc config pointer_action1         move
bspc config pointer_action2         resize_side
bspc config pointer_action3         resize_corner

# Show where new window will be opened

bspc config presel_feedback         true

# Prefix prepended to status program

bspc config status_prefix           'W'

# Insertion scheme

bspc config automatic_scheme        longest_side

# Colors

dark_moderate_blue="#5e81ac"
mint_cream="#EFF8F5"
baby_blue="#58FAF4"
black="#000000"
white="#FFFFFF"
pink_flamingo="#FA58F4"
pure_cyan="#00FFFF"
pure_magenta="#FF00FF"
vivid_red="#ff3232"
hot_pink="#ff69b4"
maroon="#800000"
up_maroon="#7b1113"
awesome="#B443F3"
pink="#F10CF1"
sky_blue="#28DECB"

# Feedback color of preselection

bspc config presel_feedback_color   $baby_blue

# Focused Border color

bspc config focused_border_color    $maroon

# Active border color

bspc config active_border_color     $pink

# Normal border color

bspc config normal_border_color     $sky_blue

# Mouse

bspc config pointer_modifier mod4
bspc config pointer_action3 resize_side
bspc config pointer_action3 resize_corner
bspc config pointer_action1 move
#sleep 1
#urxvtc -g 70x20 -title 'scratchpad'
#picom -b &
#feh --bg-scale --randomize ~/pix/wall/blurry/ &
# alacritty -t 'scratchpad' &

# Start some useful programs. Only useful if you don't use some display manager.
# If you use one, that will source ~/.xprofile so execute these programs from
# there instead.

"$HOME"/.config/bspwm/autostart.sh &
